<?php
$guid = elgg_get_logged_in_user_guid();
$sec = get_input('sec');
$sec_name = get_input('sec_name');
if ($guid && $sec) {
	//print_r('focus/add');
	$ret = get_data_row("select * from dsq_user_focus where guid='$guid' and ticker='$sec' ");
	if($ret) { //already exist
		$ret = update_data("update dsq_user_focus set time=CURRENT_TIMESTAMP() where guid='$guid' and ticker='$sec' ");
	} else {
		$ret = insert_data("insert into dsq_user_focus (guid, ticker, name) values ({$guid}, '{$sec}', '{$sec_name}')");
	}
	
	if ($ret==0) {
		$codes = get_securities_array();

		$event = new ElggObject();
		$event->subtype = 'focus_sec';
		$event->owner_guid = $guid;
		$event->container_guid = $guid;
		$event->title = $sec.' '.$codes[$sec];
		$event->security = $sec;
		$event->access_id = ACCESS_PUBLIC;
		if ($event->save()) {
		
			add_to_river('river/focus/add','focused',$guid,$event->guid);
			echo '1';
			exit;
		}
	
	}
}
?>
0